<?php
require_once('init.php');
if (!Auth::isAdmin()) {
	header('Location: login_form.php');
	exit();
}
?><!DOCTYPE html>
<html>
<head>
<title>Silesia Racing Time Battle</title>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> 
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>  
<script type="text/javascript" src="js/jquery.betterTooltip.js"></script>  
</head>
<body>
    <div id="wrapper">
        <div id="headerwrap">
        <div id="header">
           <p align="right"> Silesia Racing Time Battle EVOLution</p>
        </div>
        </div>
		<div id="topwrap">
        <div id="top_home">		
           <h2>Time Battle</h2>
        </div>
        </div>
        <div id="leftcolumnwrap">
        <div id="leftcolumn">
            <?php include_once ('menu_left.php');?>
        </div>
        </div>
        <div id="contentwrap">
        <div id="content">
		<div>   
		<p></p>
		<form action="drivertime_add.php" method="post">
		<TABLE>
			<TR>
			<?
			echo "<TD>";
				// wybór kierowców
				$driver_time = mysql_query("SELECT driver.id AS driver_id, driver.description AS driver FROM  driver  ;");
				if (!$driver_time) 
				{	
					die('Invalid query: ' . mysql_error());
				}
				$dupa=0;
				while($row2 = mysql_fetch_array($driver_time))
				  {
					if($dupa==0)
					{
						echo "<select name=driver_id>
						<option value='" . $row2['driver_id']  . "'>" . $row2['driver']  . "</option>";
					}
					echo "<option value='" . $row2['driver_id']  . "'>" . $row2['driver']  . "</option>";
					$dupa=1;
				  }
				  if($dupa<>0)
					  {
						  echo "</select>" . $row2['driver_id']  . "  ";
					  }
				echo "</TD>";
				?>

				<TD>
					 Time: 
				</TD>
				<TD>
					<input type="text" name="time"> Format(min:sec:setna)
				</TD>
			</TR>
		</TABLE>
		<input type="submit" value="Add Time">
		</form>
		</p>
		<?
		// odbieramy dane z formularza 
			$driver_id = $_POST['driver_id']; 
			$time = $_POST['time']; 

		if($driver_id and $time ) {      
     
		// dodajemy rekord do bazy 
			$ins = @mysql_query("INSERT INTO times SET driver_id='$driver_id', time_lap='$time'"); 
			 mysql_query($ins);
			if($ins) echo "Rekord został dodany poprawnie"; 
			else echo "Błąd nie udało się dodać nowego rekordu"; 
			 } 

			//echo '<pre>';
			//print_r($_POST);
			//echo '</pre>';
			//echo "INSERT INTO times SET driver_id='$driver_id', time_lap='$time'";
		?>	
		</div>
        </div>
        </div>
        <div id="rightcolumnwrap">
        <div id="rightcolumn">
			<?php include_once ('right_column.php');?>
			<p></p>
        </div>
        </div>
        <div id="footerwrap">
        <div id="footer">
            <p>Silesia Racing Time Battle</p>
        </div>
        </div>
    </div>
</body>
</html>
